import axios from "axios";
import qs from "qs";
const mode = import.meta.env.MODE;

export const selectBaiduCandidateWordApi = (wd) => {
  let params = {
    pre: "1",
    p: "3",
    ie: "utf-8",
    json: "1",
    prod: "pc",
    from: "pc_web",
    wd: wd,
    csor: wd ? wd.length : 0,
  };
  let qParams = "?" + qs.stringify(params);

  if (mode == "development") {
    return axios({
      url: "/baidu/sugrec",
      method: "GET",
      params: {
        pre: "1",
        p: "3",
        ie: "utf-8",
        json: "1",
        prod: "pc",
        from: "pc_web",
        wd: wd,
        csor: wd ? wd.length : 0,
      },
    });
  } else {
    return fetch("https://www.baidu.com/sugrec" + qParams)
      .then((response) => response.json())
      .then((data) => console.log(data))
      .catch((error) => console.error("Error:", error));
  }
};

// 测试请求
export const testApi = () => {
  return axios({
    url: "http://127.0.0.1:12005/device/select",
    method: "POST",
  });
};

// 登录
export const loginApi = () => {
  return axios({
    url: "http://106.54.233.201:11005/mg/mLogin",
    method: "POST",
    params: {
      platFormUserName: "lohand",
      platFormUserPass: "123456",
    },
  });
};

// 测试1
export const test1Api = () => {
  return axios({
    url: "https://suggestion.baidu.com/su",
    method: "GET",
    params: {
      p: 3,
      ie: "UTF-8",
      cd: "",
      wd: "lol",
    },
  });
};
